//set_order_quantity() include_once('Bag.inc'); session_start(); foreach($_POST as $item_number => $quantity){ if($_POST[$item_number] != 0) $_SESSION['bag']->new_order_item($item_number,$quantity); } header("Location:bag_content.php"); //新增訂購便當項目 function new_order_item($item_number,$quantity){ $sql = "SELECT lunchbox_number,lunchbox_name,price FROM lunchboxtype WHERE lunchbox_number ='$item_number'"; $search = mysql_db_query("test",$sql); list($lunchbox_number,$lunchbox_name,$single_cost) = mysql_fetch_array($search); $new_lunchbox_number = array($lunchbox_number=>$lunchbox_number); $this->lunchbox_number = array_merge($this->lunchbox_number,$new_lunchbox_number); $new_lunchbox_name = array($lunchbox_number=>$lunchbox_name); $this->lunchbox_name = array_merge($this->lunchbox_name,$new_lunchbox_name); $new_single_cost = array($lunchbox_number=>$single_cost); $this->single_cost = array_merge($this->single_cost,$new_single_cost); $new_quantity = array($lunchbox_number=>$quantity); $this->quantity = array_merge($this->quantity,$new_quantity); $price = $quantity * $single_cost; $new_price = array($lunchbox_number=>$price); $this->price = array_merge($this->price,$new_price); $this->total_cost = array_sum($this->price); }